package com.numberma.permissionservice.controller;

import com.numberma.permissionservice.Result.Result;
import com.numberma.permissionservice.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class PermissionController {
      @Autowired
      private PermissionService permissionservice;
      @PostMapping("/permissions/bindDefaultRole")
      public  Result bindDefaultRole(@RequestParam("userId") Long UserId) {
            log.info("请求到达，id: {}", UserId); // 添加日志
           return permissionservice.bindDefaultRole(UserId);

      }
      @GetMapping("/permissions/getUserRoleCode/{UserId}")
      public String getUserRole(@PathVariable Long UserId) {
            return permissionservice.getUserRole(UserId);
      }
      @GetMapping("/permissions/getUserIdsByRoleCode")
      public List<Integer> getUserIdsByRoleCode(String roleCode) {
            return permissionservice.getUserIdsByRoleCode(roleCode);
      }
      @PostMapping("/permissions/upgradeToAdmin")
      public void upgradeToAdmin(Long UserId) {
            log.info("请求到达，id: {}", UserId);
            permissionservice.upgradeToAdmin(UserId);
      }
      @PostMapping("/permissions/downgradeToUser")
      public void downgradeToUser(Long UserId) {
            permissionservice.downgradeToUser(UserId);
      }
}

